package com.dsh.authorityManagement.service.impl;

import com.dsh.authorityManagement.dao.AdminPermissionDao;
import com.dsh.authorityManagement.entity.AdminPermission;
import com.dsh.authorityManagement.entity.RoleModel;
import com.dsh.authorityManagement.entity.dto.IdDto;
import com.dsh.authorityManagement.entity.vo.IdsVo;
import com.dsh.authorityManagement.entity.vo.PermissionMenuVo;
import com.dsh.authorityManagement.entity.vo.UserForPermissionVo;
import com.dsh.authorityManagement.entity.vo.UserIdAndPermissionIdVo;
import com.dsh.authorityManagement.service.AdminPermissionService;
import com.dsh.storeManagement.dao.AdminFranchiseLevelDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class AdminPermissionImpl implements AdminPermissionService {
    @Autowired
    AdminPermissionDao adminPermissionDao;
    @Override
    public List<AdminPermission> selectPermissionTree() {
        List<AdminPermission> adminPermissions = adminPermissionDao.selectPermissionTree();
        return adminPermissions;
    }

    @Override
    public List<RoleModel> selectAllRole() {
        List<RoleModel> roleModels = adminPermissionDao.selectAllRole();
        return roleModels;
    }

    @Override
    public void insertPermissionForRoleAndStoreAndAdmin(Integer[] permissionIds, int userId, int storeId, int roleId) {
        for (Integer id : permissionIds) {
            IdsVo idsVo = new IdsVo();
            idsVo.setPermissionId(id);
            idsVo.setRoleId(roleId);
            idsVo.setStoreId(storeId);
            idsVo.setUserId(userId);
            this.adminPermissionDao.insertPermissionForRoleAndStoreAndAdmin(idsVo);
        }
    }

//    @Override
//    public int selectShipForUserIdAndPermission() {
//
//        return i;
//    }

    @Override
    public void deleteShip(List<UserIdAndPermissionIdVo> userIdAndPermissionIdVoList) {
        for (int i = 0; i <userIdAndPermissionIdVoList.size() ; i++) {
            int i1 = adminPermissionDao.selectShipForUserIdAndPermission(userIdAndPermissionIdVoList.get(i).getUserId(), userIdAndPermissionIdVoList.get(i).getPermissionId());
            this.adminPermissionDao.deleteShip(i1);
        }
    }

    @Override
    public List<UserForPermissionVo> selectUserForRoleAndStore(int pId, int sId) {
        List<UserForPermissionVo> userForPermissionVos = adminPermissionDao.selectUserForRoleAndStore(pId, sId);
        return userForPermissionVos;
    }

    @Override
    public List<PermissionMenuVo> selectLoginSuccessMenu(int userId) {
        List<PermissionMenuVo> permissionMenuVos = adminPermissionDao.selectLoginSuccessMenu(userId);
        return permissionMenuVos;
    }

}
